/*    */ package com.zimbra.cs.service.doc;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.MailConstants;
/*    */ import com.zimbra.common.util.StringUtil;
/*    */ import com.zimbra.cs.doc.Diff;
/*    */ import com.zimbra.cs.doc.Diff.Chunk;
/*    */ import com.zimbra.cs.doc.Diff.Type;
/*    */ import com.zimbra.cs.mailbox.Document;
/*    */ import com.zimbra.cs.mailbox.MailItem.Type;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.OperationContext;
/*    */ import com.zimbra.cs.service.util.ItemId;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.io.IOException;
/*    */ import java.util.Collection;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class DiffDocument
/*    */   extends DocDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 40 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 41 */     Mailbox mbox = getRequestedMailbox(zsc);
/* 42 */     OperationContext octxt = getOperationContext(zsc, context);
/*    */     
/* 44 */     Element doc = request.getElement("doc");
/* 45 */     String idStr = doc.getAttribute("id", null);
/* 46 */     int v1 = (int)doc.getAttributeLong("v1", -1L);
/* 47 */     int v2 = (int)doc.getAttributeLong("v2", -1L);
/*    */     
/* 49 */     ItemId id = new ItemId(idStr, zsc);
/* 50 */     Document r1 = (Document)mbox.getItemRevision(octxt, id.getId(), MailItem.Type.UNKNOWN, v1);
/* 51 */     Document r2 = (Document)mbox.getItemRevision(octxt, id.getId(), MailItem.Type.UNKNOWN, v2);
/*    */     
/* 53 */     Element response = zsc.createElement(MailConstants.DIFF_DOCUMENT_RESPONSE);
/*    */     try
/*    */     {
/* 56 */       Collection<Diff.Chunk> diffResult = Diff.getResult(r1.getContentStream(), r2.getContentStream());
/* 57 */       for (Diff.Chunk c : diffResult) {
/* 58 */         Element chunk = response.addElement("chunk");
/* 59 */         chunk.addAttribute("disp", c.disposition.toString());
/* 60 */         chunk.setText(StringUtil.join("\n", c.content));
/*    */       }
/*    */     } catch (IOException e) {
/* 63 */       throw ServiceException.FAILURE("can't diff documents", e);
/*    */     }
/*    */     
/* 66 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/doc/DiffDocument.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */